package com.itheima.arithmetic.array;

import java.io.BufferedReader;
import java.io.FileInputStream;
import java.io.InputStreamReader;

public class Array {

    /**
     * 经典面试题: 一个文件(10G)里面包含全国的年龄数据, 现在要求统计每一个年龄有多少人?
     * 给定机器为单台 + 双核CP + 2G内存. 不得使用现成的容器, 如Map, Set等
     */

    public static void main(String[] args) throws Exception {
        String fileName = "C:\\Users\\user\\Desktop\\年龄.txt";

        InputStreamReader isr = new InputStreamReader(new FileInputStream(fileName), "UTF-8");

        BufferedReader bf = new BufferedReader(isr);

        int total = 0;
        String str = null;
        int aa [] = new int[150];
        while ((str = bf.readLine()) != null) {
            int age = Integer.parseInt(str);
            aa[age] ++;
            total ++;
        }

        System.out.println("总数据:" + total);

        for (int i = 0; i < aa.length; i++) {
            System.out.println(i + ":" + aa[i]);
        }
    }

}
